package io.osw.modules.stock.controller;

import java.util.Arrays;
import java.util.Map;
import java.util.Date;
import io.osw.common.validator.ValidatorUtils;
import io.osw.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import io.osw.modules.stock.entity.TblUploadLineEntity;
import io.osw.modules.stock.service.TblUploadLineService;
import io.osw.common.utils.PageUtils;
import io.osw.common.utils.R;



/**
 * 导入行表
 *
 * @author guxiaoguang
 * @email xuebai864627555@gmail.com
 * @date 2019-01-16 17:56:51
 */
@RestController
@RequestMapping("stock/tbluploadline")
public class TblUploadLineController extends AbstractController{
    @Autowired
    private TblUploadLineService tblUploadLineService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("stock:tbluploadline:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tblUploadLineService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{lineId}")
    @RequiresPermissions("stock:tbluploadline:info")
    public R info(@PathVariable("lineId") Long lineId){
        TblUploadLineEntity tblUploadLine = tblUploadLineService.selectById(lineId);

        return R.ok().put("tblUploadLine", tblUploadLine);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("stock:tbluploadline:save")
    public R save(@RequestBody TblUploadLineEntity tblUploadLine){
        tblUploadLine.setCreateTime(new Date());
        tblUploadLine.setCreateBy(getUserId());
        tblUploadLineService.insert(tblUploadLine);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("stock:tbluploadline:update")
    public R update(@RequestBody TblUploadLineEntity tblUploadLine){
        ValidatorUtils.validateEntity(tblUploadLine);
        tblUploadLine.setUpdateTime(new Date());
        tblUploadLine.setUpdateBy(getUserId());
        tblUploadLineService.updateAllColumnById(tblUploadLine);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("stock:tbluploadline:delete")
    public R delete(@RequestBody Long[] lineIds){
        tblUploadLineService.deleteBatchIds(Arrays.asList(lineIds));

        return R.ok();
    }

}
